﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DependencyResolverConfig.cs" company="ecblog.codeplex.com">
//   emrecoskun.net - ibrahimatay.com
// </copyright>
// <summary>
//   Defines the DependencyResolverConfig type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace EcBlog
{
    using System.ComponentModel.Composition.Hosting;
    using System.Data.Entity;
    using System.Web.Mvc;

    using EcBlog.Composition;
    using EcBlog.Data.Sql;

    using WebMatrix.WebData;

    public class DependencyResolverConfig
    {
        public static void RegisterContainer()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<EcModelContext, Migrations.Configuration>());
            // Database.SetInitializer(new CreateDatabaseIfNotExists<EcModelContext>());
            Database.SetInitializer<EcModelContext>(null);
            var context = new EcModelContext();
            context.Database.Initialize(force: true);
            WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "UserId", "UserName", autoCreateTables: true);
            

            var catalog = new AggregateCatalog(new AssemblyCatalog(typeof(PageRepository).Assembly));
            var container = new CompositionDependencyResolver(catalog, DependencyResolver.Current);

            DependencyResolver.SetResolver(container);
        }
    }
}